package com.marvels.approve.consum.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.marvels.approve.common.dto.CmsEmployeeInfoDTO;
import com.marvels.approve.consum.ApproveConsumerUmApi;
import com.marvels.approve.loan.dto.RealNameAuthentication;
import com.marvels.approve.loan.dto.ZxDataRespDTO;
import com.marvels.approve.process.dto.SysUserDTO;
import com.marvels.common.dto.ChannelUserDTO;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.coreservice.service.AssistantUserService;
import com.marvels.dubbo.umservice.service.RealNameAuthentyService;
import com.marvels.dubbo.umservice.service.UserInfoService;

import cn.hutool.core.bean.BeanUtil;

@Component
public class ApproveConsumUmImpl implements ApproveConsumerUmApi{

	@Autowired
	private UserInfoService userInfoService;
	
	@Autowired
	private AssistantUserService aAssistantUserService;
	
	@Autowired
	private RealNameAuthentyService realNameAuthenticationService;
	
	@Override
	public RealNameAuthentication querByIdentiyCardNo(String custIdCard) {
		try {
			com.fintech.user.entity.RealNameAuthentication apiResult = realNameAuthenticationService.querByIdentiyCardNo(custIdCard);
			RealNameAuthentication result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), RealNameAuthentication.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerUmApi.querByIdentiyCardNo direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerUmApi.querByIdentiyCardNo error", e);
			return null;
		}
	}

	@Override
	public SysUserDTO queryUserByMobileNo(String account, String type) {
		try {
			com.fintech.user.entity.User apiResult = userInfoService.queryUserByMobileNo(account, type);
			SysUserDTO result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), SysUserDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerUmApi.queryUserByMobileNo direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerUmApi.queryUserByMobileNo error", e);
			return null;
		}
	}

	@Override
	public ChannelUserDTO queryUserById(Integer userId) {
		try {
			com.fintech.user.entity.User apiResult = userInfoService.queryUserById(userId);
			ChannelUserDTO result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), ChannelUserDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerUmApi.queryUserById direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerUmApi.queryUserById error", e);
			return null;
		}
	}

	@Override
	public List<ChannelUserDTO> queryByClientManagerId(Integer clientManagerId, Integer start, Integer limit) {
		try {
			List<com.fintech.user.entity.User> apiResult = aAssistantUserService.queryByClientManagerId(clientManagerId,start,limit);
			List<ChannelUserDTO> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), ChannelUserDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerUmApi.queryByClientManagerId direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerUmApi.queryByClientManagerId error", e);
			return null;
		}
	}

	@Override
	public CmsEmployeeInfoDTO queryEmployeeByUserId(Integer userId) {
		MarvelsLogUtil.getInstance().info("ApproveConsumerUmApi.queryEmployeeByUserId direct call success, but unrealized!");
		return null;
	}

}
